package com.inspur.cloud.enums;

public enum PermissionEnum {
    HDFS_READ(1,"read"),
    HDFS_WRITE(1,"write"),
    HDFS_EXECUTE(1,"execute"),

    HBASE_READ(2,"read"),
    HBASE_WRITE(2,"write"),
    HBASE_CREATE(2,"create"),
    HBASE_ADMIN(2,"admin"),

    HIVE_SELECT(3,"select"),
    HIVE_UPDATE(3,"update"),
    HIVE_CREATE(3,"create"),
    HIVE_DROP(3,"drop"),
    HIVE_ALTER(3,"alter"),
    HIVE_INDEX(3,"index"),
    HIVE_LOCK(3,"lock"),
    HIVE_ALL(3,"all"),
    HIVE_READ(3,"read"),
    HIVE_WRITE(3,"write"),
    HIVE_REPLADMIN(3,"repladmin"),
    HIVE_SERVICEADMIN(3,"serviceadmin"),
    HIVE_TEMPUDFADMIN(3,"tempudfadmin"),

    YARN_SUBMIT(4,"submit-app"),
    YARN_ADMIN(4,"admin-queue"),

    KAFKA_PUBLISH(5,"publish"),
    KAFKA_CONSUME(5, "consume");
//    KAFKA_CONFIGURE(5,"configure"),
//    KAFKA_DESCRIBE(5,"describe"),
//    KAFKA_CREATE(5,"create"),
//    KAFKA_DELETE(5,"delete"),
//    KAFKA_ADMIN(5,"kafka_admin");



    PermissionEnum(Integer resourceType, String permission) {
        this.resourceType = resourceType;
        this.permission = permission;
    }

    private Integer resourceType;

    private String permission;

    public Integer getResourceType() {
        return resourceType;
    }

    public void setResourceType(Integer resourceType) {
        this.resourceType = resourceType;
    }

    public String getPermission() {
        return permission;
    }

    public void setPermission(String permission) {
        this.permission = permission;
    }

    public static String getAllPermissionByType(Integer type){
        String allPermission = "";
        if (type != null) {
            for (PermissionEnum e : PermissionEnum.values()) {
                if (e.getResourceType() == type) {
                    allPermission += e.getPermission() + "|";
                }
            }
            if (allPermission.endsWith("|")) {
                allPermission = allPermission.substring(0,allPermission.length()-1);
            }
        }
        return allPermission;
    }


}
